<template>
	<view class="addEmployee">
		<uni-forms :rules="rulesWxForm" ref="form" :modelValue="form" label-position="top">
	
	
	
	
			<uni-forms-item label="员工姓名" name="staffName" required labelWidth="180px">
				<uni-easyinput trim="all" v-model="form.staffName" placeholder="请输入员工姓名" />
	
			</uni-forms-item>
			<uni-forms-item   label="联系电话" name="phone" required labelWidth="180px">
				<uni-easyinput maxlength="11" trim="all" v-model="form.phone" placeholder="请输入联系电话" />
	
			</uni-forms-item>
			<uni-forms-item   label="登录账号" name="staffCode" required labelWidth="180px">
				<uni-easyinput maxlength="11" trim="all" v-model="form.staffCode" placeholder="请输入登录账号" />
	
			</uni-forms-item>
			<uni-forms-item  label="登录密码" name="password" required labelWidth="180px">
				<uni-easyinput type="password" trim="all" v-model="form.password" placeholder="请输入登录密码" />
	
			</uni-forms-item>
		
			<view class="sumbit-btn flex" @click.stop="saveInfo('form')">
				保存信息
			</view>
	
	
		</uni-forms>
	</view>
</template>

<script>
	export default {
		data() {
			return {
			   merchantId: uni.getStorageSync('merchantId'),
		         //员工状态  1 正常  2冻结   默认传1
				 staffStatus:1,
				// 商家注册
				form:{
					// 员工姓名
					staffName:'',
					// 电话
					phone:'',
					// 登录账号
					staffCode:'',
					// 密码
					password:'',
				
				},
				rulesWxForm: {
					staffName: {
						rules: [{
							required: true,
							errorMessage: '请输入员工姓名'
						}]
					},
					phone: {
						rules: [{
							required: true,
							errorMessage: '请输入联系电话'
						}]
					},
					staffCode: {
						rules: [{
							required: true,
							errorMessage: '请输入登录账号'
						}]
					},
					password:{
						rules: [{
							required: true,
							errorMessage: '请输入登录密码'
						}]
					
					}
				
				},
				
				
			}
		},
		onLoad(options) {
		   if (!(Object.keys(options).length === 0)) {
		    console.log(options)
			this.$sun.assignObject(this.form, {
				...options
			})
		   } else {
		     console.log('对象为空');
		   }
			
		},
		methods:{
		saveInfo(formName) {
			console.log(formName)
			this.$refs[formName].validate((err, formData) => {
				// 如果校验成功 ，err 返回 null
				if (err) {
					console.log(err, formData)
					return
				}else{
					this.$at.uniDoFunc({
						key: 'release',
						success: async () => {
							this.$at.lockKey('release');
						 
						 const result = await this.$http.post({
						 	url: this.$api.addStaffList,
						 	data: {
						 		    merchantId:this.merchantId,
						 			staffCode:this.form.staffCode,
						 			staffName:this.form.staffName,
						 			password:this.form.password,
						 			phone:this.form.phone,
						 			status:this.staffStatus,
						 			username:uni.getStorageSync('staffCode'),
						 	},
						 
						 
						 });
						 if(result.code==2000){
							 this.$sun.toast('添加成功','none')
							 this.$at.releaseKey('release');
						 }else{
							 this.$sun.toast(result.msg,'none')
							 this.$at.releaseKey('release');
						 }
					       
						}
					});
				}
				console.log('error', err)
			}).then(async res => {
				
		
		
			})
		
		},
		}
	}
	
</script>

<style lang="less" scoped>
	page{
		background-color: #fff;
	}
	.addEmployee{
		padding: 45rpx;
		.sumbit-btn {
			width: 670rpx;
			position: fixed;
		
			bottom: 50rpx;
		
			height: 100rpx;
			color: #fff;
			border-radius: 10px;
		
			background-color: #1890FF;
		}
	}

</style>